import { baseUrlApi } from "@/api/utils";
import { http } from "@/utils/http";

interface AdbDeviceI {
  udid: string;
  name: string;
  imei: string;
  status: string;
  remark?: string;
}

export type AdbDeviceApiResult = {
  success: boolean;
  data: AdbDeviceI[];
  msg?: string;
  page?: number;
  limit?: number;
  total?: number;
};

interface DeviceI {
  id: number;
  udid: string;
  name: string;
  imei: string;
  status: string;
  remark?: string;
}

export type DeviceApiResult = {
  success: boolean;
  page: number;
  limit: number;
  total: number;
  data: DeviceI[];
};

export const apiGetAdbDevices = async (filter = {}) => {
  return http
    .request<Promise<AdbDeviceApiResult>>(
      "get",
      baseUrlApi("api/adb/list/"),

      { params: { ...filter } }
    )
    .then((res: any) => {
      return res;
    })
    .catch(err => {
      throw err;
    });
};

export const apiGetDevices = async (params = {}) => {
  return http
    .request<Promise<DeviceApiResult>>("get", baseUrlApi("devices/"), {
      params: params
    })
    .then((res: any) => {
      return res;
    })
    .catch(err => {
      throw err;
    });
};

export const apiUpdateDevice = async (devID: number, data: any) => {
  return http.request("put", baseUrlApi("api/devices/" + devID + "/update/"), {
    data
  });
};
export const apiDeleteDevice = async (devID: number) => {
  return http.request("put", baseUrlApi("api/devices/" + devID + "/delete/"));
};
